home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / 13h_kit / font.doc < prev    next >
Text File  |  1991-07-04  |  8KB  |  208 lines

  1. >>> FONT.DOC
  2.  
  3. ****************************************************************************
  4.  
  5. Images.Hpp and Images.Cpp along with this document file are copyright 1991
  6. by the Gamers Programming Workshop, GAMERS forum, Compuserve (GO GAMERS,
  7. section 11). The code and related document are free for use, distribution,
  8. and modification, provided the following conditions are met:
  9.  
  10.     1. no commercial use of this source code or documents is permitted.
  11.     2. no fee may be charged beyond disk duplication cost for any of this
  12.        material.
  13.     3. If the code is upgraded or modified a copy of the modification must
  14.        be uploaded to section 11 of the GAMERS forum on Compuserve. All
  15.        modifications must be documented and the author's name included in
  16.        the source code header block, and the subsequent file package must
  17.        include all the original doc files as well as any additions. If you
  18.        modify or add functions please update the function list below.
  19.  
  20. ****************************************************************************
  21.  
  22. Images.hpp and images.cpp provide basic tools for working in graphics mode
  23. 13h, the 256 color standard vga mode, which has become the most popular for
  24. producing high quality gaming software. The following files are required to
  25. use the tools in this package:
  26.  
  27.     IMAGES.HPP   - the image tools header file
  28.     IMAGES.CPP   - image tools function definitions
  29.     KEYBOARD.HPP - low level keyboard interface header file
  30.     KEYBOARD.CPP - functions required by the font class in images.hpp
  31.  
  32. A demo of the functions in this package is included, as IDEMO.EXE.
  33.  
  34. NOTE: Compile these modules in the Large model (pointers default to far).
  35.  
  36. *****************************************************************************
  37.  
  38. Images.Hpp contains the declaration of a class font, which is an object
  39. class designed to do basic operations with bitmapped text in VGA mode 13h
  40. (standard 256 color graphics mode). There is also a source file included
  41. for GETFONT.EXE which can be used to capture your own fonts which have been
  42. saved in .PCX format.
  43.  
  44.  
  45. USING THE FONT CLASS
  46.  
  47.  
  48. The font class contains a font bitmap, as well as related data, and meth-
  49. ods for displaying and reading text strings, setting the text style, and
  50. checking for a valid installation. An object of this class is defined as
  51. follows:
  52.             font small("csfont1.fnt");
  53.  
  54. or
  55.             font *small
  56.             small = new font("csfont1.fnt");
  57.  
  58. This statement generates a call to the font constructor, which performs
  59. 5 important tasks. First the font file is opened, then the font header and
  60. character width table are read into data space in the font object. It then
  61. allocates enough memory for the cursor mask, and reads that in from disk.
  62. Last, memory is allocated and the font bitmap itself is loaded. If at any
  63. point in this process an error occurs the constructor terminates and the
  64. function sets the font status variable to 0. This variable is returned by
  65. a call to installed(). If the initialization is successful the font is set
  66. to default style : foreground=0, background=15, character tab=1, opacity=
  67. opaque, space=5. This yields black on white text which overwrites the cur-
  68. rent image. The letters are spaced 1 pixel apart, and a space character is
  69. worth 5 pixels.
  70.  
  71. All allocated memory is freed by the destructor as soon as the font object
  72. goes out of scope and is no longer needed, or if it is deleted (if opened
  73. using the new operator).
  74.  
  75. The interface to the font object is contained in these functions:
  76.  
  77. ****************************************************************************
  78.  
  79. void setstyle(int f_grnd,int b_grnd,short char_tab,opacity o,char space_wid);
  80.  
  81. >>    setstyle() selects the style of text that will be used on the next call
  82. to show(). Call with foreground color in f_grnd, background color in b_grnd,
  83. pixels between characters in char_tab, background treatment in o, and width
  84. of space character (ascii 32) in pixels in space_wid. Possible values are:
  85.  
  86.     f_grnd, b_grnd : 0..255
  87.     char_tab       : 0..320
  88.     space_wid      : 0..10
  89.     o              : trans,opaque
  90.  
  91. When o is set to trans the value in b_grnd is ignored, and only the fore-
  92. ground color of the text is plotted. When o is opaque the background color
  93. is plotted.
  94.  
  95. ****************************************************************************
  96.  
  97. int getforecolor();
  98.  
  99. >>    returns the current text foreground color
  100.  
  101. ****************************************************************************
  102.  
  103. int getbackcolor();
  104.  
  105. >>    returns the current text background color
  106.  
  107. ****************************************************************************
  108.  
  109. void show(int x, int y, char *str);
  110.  
  111. >>    displays the string of characters pointed to by str, with the top left
  112. corner of the first character displayed at (x,y). This function does not
  113. return a value. The displayed text is not clipped at the screen edge, but
  114. will wrap into the next scan line.
  115.  
  116. ****************************************************************************
  117.  
  118. void readstr(int x, int y,char *str, char length, char mask);
  119.  
  120. >>    readstr() reads in a series of characters entered at the keyboard and
  121. stores them in the string pointed to by str. The resulting string is prop-
  122. erly formatted with a terminating null '\0' character. The entered text is
  123. echoed to the screen at (x,y), as in show() above. The function returns
  124. when the user presses enter, or the string reaches length bytes. As the
  125. entered text is echoed to screen the function moves a blinking cursor, the
  126. mask for which is stored as part of the font data. A good improvement to
  127. the font class would be to allow the cursor mask to be redefined to something
  128. other than the font default. Backspace is supported, but insert and delete
  129. are not, and they would be another good improvement. The function gets its
  130. keystrokes from the getfilteredkey() function defined in KEYBOARD.HPP. The
  131. mask value determines which characters are passed through. See the definition
  132. of the mask types in KEYBOARD.DOC.
  133.  
  134. ****************************************************************************
  135.  
  136. int installed();
  137.  
  138. >>    installed() should be called immediately after defining an instance of
  139. a font object, to ensure that there were no errors during initialization
  140. of the font. The funtion returns 1 if no errors occured, or 0 if an error
  141. has occured. Possible errors are memory allocation and file access errors.
  142.  
  143. ****************************************************************************
  144.  
  145.  
  146. The following is an example:
  147.  
  148.     #include <stdio.h>
  149.     #include "images.h"
  150.     #include "keyboard.h"
  151.  
  152.     void main() {
  153.         char *str;
  154.  
  155.         // set up graphics mode
  156.  
  157.         _setgraphmode();
  158.  
  159.         // clear the screen to white
  160.  
  161.         clearscr(15);
  162.  
  163.         // initialize csfont1.fnt from the current directory
  164.  
  165.         font small("csfont1.fnt");
  166.  
  167.         // check for successful installation
  168.  
  169.         if (!small.installed()) {
  170.             printf("error installing font object\n");
  171.             return;
  172.         }
  173.  
  174.         // set style to black on black, 1 pixel between characters, back-
  175.         // ground is transparent, space=5
  176.  
  177.         small.setstyle(0,0,1,trans,5);
  178.  
  179.         // display a string at 10,10
  180.  
  181.         small.show(10,10,"This black text does not overwrite the background");
  182.  
  183.         // set style to blue on white, background is opaque
  184.  
  185.         small.setstyle(9,15,1,opaque,5);
  186.         small.show(10,10,"This blue on white text does overwrite it");
  187.         clearscr(15);
  188.         small.show(10,10,"Now type in a text string, then press enter.");
  189.  
  190.         // read in a string and echo to screen at 10,20
  191.  
  192.         small.readstr(10,20,str,30);
  193.         small.show(10,30,"Here is the string you entered:");
  194.         small.show(10,40,str);
  195.         small.show(50,180,"press any key to exit");
  196.         while (!kbhit());
  197.     }
  198.  
  199.  
  200. For information on using the getfont source to capture your own fonts see
  201. GETFONT.DOC
  202.  
  203. Support:
  204.  
  205. Support for this code will be provided as and where possible through messages
  206. posted to 76605,2346 in the Game Design section (sec. 11) of the Gamers
  207. Forum on Compuserve. Sorry, but no telephone support is possible.
  208.